/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * PlaylistCellWithArtPanel.java
 *
 * Created on Mar 8, 2009, 2:36:51 PM
 */
package com.bff.slimserver.musicjukebox.ui.components.radio;

import com.bff.bjj.ui.component.ColorProperties;
import com.bff.slimserver.musicjukebox.lib.JukeboxProperties;
import com.bff.bjj.utils.Utils;
import java.awt.Color;
import java.awt.Component;
import java.awt.Image;
import java.net.URL;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import org.bff.slimserver.SlimServer;
import org.bff.slimserver.exception.SlimConnectionException;
import org.bff.slimserver.musicobjects.radio.SlimAvailableRadio;

/**
 *
 * @author Music
 */
public class RadioCellPanel extends javax.swing.JPanel implements RadioCellPanelIface {
 
    private SlimServer slimServer;
    private SlimAvailableRadio radio;

    /** Creates new form PlaylistCellWithArtPanel */
    public RadioCellPanel(SlimAvailableRadio radio) {
        setRadio(radio);
        try {
            setSlimServer(JukeboxProperties.getInstance().getSlimServer());
        } catch (SlimConnectionException ex) {
            Logger.getLogger(RadioCellPanel.class.getName()).log(Level.SEVERE, null, ex);
        }
        initComponents();

        try {

            Image image = ImageIO.read(new URL("http://" + getSlimServer().getServer() + ":" + getSlimServer().getWebPort() + "/" + radio.getIcon()));
            double scale = 50.0/ image.getHeight(lblIcon);

            lblIcon.setIcon(Utils.scale(image, scale, lblIcon));

            lblName.setText(radio.getName());

        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("Something is probably null");
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        detailPanel = new javax.swing.JPanel();
        lblIcon = new javax.swing.JLabel();
        lblName = new javax.swing.JLabel();

        setLayout(new java.awt.BorderLayout());

        detailPanel.add(lblIcon);

        lblName.setText("jLabel3");
        detailPanel.add(lblName);

        add(detailPanel, java.awt.BorderLayout.WEST);
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel detailPanel;
    private javax.swing.JLabel lblIcon;
    private javax.swing.JLabel lblName;
    // End of variables declaration//GEN-END:variables

    public void setEven() {
        setBackground(ColorProperties.LIST_BACKGROUND_EVEN);
    }

    public void setOdd() {
        setBackground(ColorProperties.LIST_BACKGROUND_ODD);
    }

    public void setCurrentPlaying() {
        setForeground(ColorProperties.PLAYLIST_CURRENT_PLAYING_FOREGROUND);
    }

    public void setSelected() {
        setForeground(ColorProperties.LIST_FOREGROUND_SELECTED);
        setBackground(ColorProperties.LIST_BACKGROUND_SELECTED);
        lblName.setBackground(ColorProperties.LIST_BACKGROUND_SELECTED);
    }

    public void setNotSelected() {
        setForeground(ColorProperties.LIST_FOREGROUND);
    }

    @Override
    public void setBackground(Color bg) {
        super.setBackground(bg);
        //detailPanel.setBackground(bg);
        if (detailPanel != null) {
            detailPanel.setBackground(bg);
            lblIcon.setBackground(bg);
        }
    }

    @Override
    public void setForeground(Color fg) {
        super.setForeground(fg);
        if (detailPanel != null) {
            detailPanel.setForeground(fg);
            lblIcon.setForeground(fg);
        }
        setLabelColors(fg);
    }

    private void setLabelColors(Color color) {
        if (lblIcon != null) {
            lblName.setForeground(color);
            lblIcon.setForeground(color);
        }
    }

    @Override
    public Component getPanel() {
        return this;
    }

    public void setCurrent() {
        setLabelColors(ColorProperties.PLAYLIST_CURRENT_PLAYING_FOREGROUND);
    }

    public void setNotCurrent() {
        setLabelColors(ColorProperties.LIST_FOREGROUND_SELECTED);
    }

    /**
     * @return the radio
     */
    public SlimAvailableRadio getRadio() {
        return radio;
    }

    /**
     * @param radio the radio to set
     */
    public void setRadio(SlimAvailableRadio radio) {
        this.radio = radio;
    }

    /**
     * @return the slimServer
     */
    public SlimServer getSlimServer() {
        return slimServer;
    }

    /**
     * @param slimServer the slimServer to set
     */
    public void setSlimServer(SlimServer slimServer) {
        this.slimServer = slimServer;
    }
}
